---
title: "10 Discrete IVs and Other"
author: "Colin Kuehl"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output: html_document
editor_options: 
  chunk_output_type: console
---

## Set-Up

Packages

```{r}
library(foreign)
library(ggcorrplot)
library(tidyverse)
library(stargazer)
library(modelsummary)
```

Set your working directory and load the height wage data(HeightWage_MenWomenUS_HW.csv).

```{r}
setwd("~/Dropbox/POLS 641/CMU Su26/cmucourse26/ClassCode/Day 10")
hw <- read.csv("HeightWage_MenWomenUS_HW.csv")
```

###Codebook in html - knit now to show in viewer 31b8e172-b470-440e-83d8-e6b185028602:dAB5AHAAZQA6AE8AQQBCAGwAQQBHAFkAQQBOAFEAQgBoAEEARABjAEEATgB3AEEAeQBBAEMAMABBAFoAQQBCAGsAQQBEAFkAQQBNAHcAQQB0AEEARABRAEEATgBnAEEAeQBBAEQASQBBAEwAUQBBADQAQQBEAFEAQQBZAGcAQgBtAEEAQwAwAEEAWQBRAEIAbQBBAEQARQBBAE8AUQBBADUAQQBEAFUAQQBZAFEAQQB4AEEARwBJAEEATQBnAEIAaQBBAEQAawBBAAoAcABvAHMAaQB0AGkAbwBuADoATgBRAEEAMABBAEQAawBBAAoAcAByAGUAZgBpAHgAOgAKAHMAbwB1AHIAYwBlADoAUABBAEIAMABBAEcARQBBAFkAZwBCAHMAQQBHAFUAQQBJAEEAQgBqAEEARwB3AEEAWQBRAEIAegBBAEgATQBBAFAAUQBBAGkAQQBIAFEAQQBZAFEAQgBpAEEARwB3AEEAWgBRAEEAZwBBAEgAUQBBAFkAUQBCAGkAQQBHAHcAQQBaAFEAQQB0AEEARwBJAEEAYgB3AEIAeQBBAEcAUQBBAFoAUQBCAHkAQQBHAFUAQQBaAEEAQQBnAEEASABRAEEAWQBRAEIAaQBBAEcAdwBBAFoAUQBBAHQAQQBHAGcAQQBiAHcAQgAyAEEARwBVAEEAYwBnAEEAZwBBAEgAUQBBAFkAUQBCAGkAQQBHAHcAQQBaAFEAQQB0AEEARwBNAEEAYgB3AEIAd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EARABZAEEAUABBAEEAdgBBAEgAUQBBAFoAQQBBACsAQQBBAG8AQQBQAEEAQgAwAEEARwBRAEEAUABnAEIAWABBAEcAVQBBAGMAdwBCADAAQQBDAEEAQQBLAEEAQQB4AEEAQwBBAEEAUABRAEEAZwBBAEgAawBBAFoAUQBCAHoAQQBDAHcAQQBJAEEAQQB3AEEAQwBBAEEAUABRAEEAZwBBAEcANABBAGIAdwBBAHAAQQBEAHcAQQBMAHcAQgAwAEEARwBRAEEAUABnAEEASwBBAEQAdwBBAEwAdwBCADAAQQBIAEkAQQBQAGcAQQBLAEEARAB3AEEATAB3AEIAMABBAEcASQBBAGIAdwBCAGsAQQBIAGsAQQBQAGcAQQA4AEEAQwA4AEEAZABBAEIAaABBAEcASQBBAGIAQQBCAGwAQQBEADQAQQAKAHMAdQBmAGYAaQB4ADoA:31b8e172-b470-440e-83d8-e6b185028602

## Exploring Wage

Explore the data, we are mostly interested in wage:

```{r}


```

```{r}
summary(hw$wage96)
hist(hw$wage96)

summary(lm(wage96 ~ esteem80, data=hw))

```

Using just continuous variables, create a multivariate model predicting wage. Practice our interpretation.

```{r}


```

## Dummy Variables

Can add to our multivariate regression

```{r}
table(hw$white)

table(hw$male)

ck1a <- (lm(wage96~male, data=hw))#Tells us average for males and non-males
summary(ck1a)

hw %>% group_by(male) %>% summarise(mean=mean(wage96, na.rm=T))
13.37+1.51

t.test(hw$wage96[hw$male==1], hw$wage96[hw$male==0], var.equal = FALSE)

plot(hw$male,hw$wage96, ylim=c(0,25)) #Really zooming in. Black lines are just a bunch of dots
abline(h=13.37, col="red")
abline(h=13.37+1.51, col="blue")
abline(abline(ck1a, lty=6, col="purple"))


plot(hw$wage96~jitter(hw$male, 1), ylim=c(0,25)) #jitter will spread out your data a bit. in some cases with super large N I will take a random sample to get a better feel for the data.
abline(h=13.37, col="red")
abline(h=13.37+1.51, col="blue")
abline(abline(ck1a, lty=6, col="purple"))
```

Indicate dummy on Multivariate Regression plot

```{r}
ck3 <- lm(wage96~  age + male, data=hw) #Shows differences between males and females
summary(ck3)

plot(jitter(hw$age[hw$male==0]),(hw$wage96[hw$male==0]), col="red", pch=1, xlab="Age", ylab="Hourly Wage", main="Age as a Determinent of \n Wage by Gender", ylim=c(0,100)) #plots female  note: \n creats new line 
#Shorten ylim to show difference
points(jitter(hw$age[hw$male==1]), hw$wage96[hw$male==1], col="blue", pch=1) #plots male
legend(50,90, legend=c("Female", "Male"), col=c("red", "blue"), pch=c(1, 16), bty="n")
abline(a=11.405, b=.052, col="red") # intercept and slope from above
abline(a=(11.405+1.708), b=.052, col="blue")
```

## More Multivariate Models

```{r}
ck2 <- lm(wage96~ male+ height85 + siblings + age, data=hw) #Shows differences between males and females
summary(ck2)

ck2a <- lm(wage96~ male+ height85 + siblings + age, data=hw)
summary(ck2a)
```

Question: Does participation in high school athletics(athlets) have an affect on wage?

```{r}
summary(lm(wage96~athlets, data=hw))

summary(lm(wage96~athlets+hgc96+siblings+height85+white+clubnum, data=hw))
```

# Categorical Variables

```{r}
#Use region variables, these have already been converted into dummy variables
reg1 <-lm(wage96~norest96+norcen96+west96+south96, data=hw) #why is south NA?  . . .. perfect multicollinearity. We need a reference category
summary(reg1)

reg2 <-lm(wage96~norcen96+west96+south96, data=hw) #Take south out to compare to 
summary(reg2)#remember we interpret these coefficients as the difference between each region and the reference category. 

reg3 <-lm(wage96~hgc96+norest96+norcen96+west96, data=hw) #add in education
summary(reg3)

plot(hw$hgc96, hw$wage96, xlab="Education level", ylab="Hourly Wage", main="Education as a Determinent of \n Wage by Region", ylim=c(0,100))
abline(a=-9.073, b=1.634, col="red") # The South
abline(a=(-9.073+3.97), b=1.634, col="blue") #Northeast
abline(a=(-9.073+1.613), b=1.634, col="hotpink") #NorthCentral
abline(a=(-9.073+2.739), b=1.634, col="green") #West
legend(0,95, legend=c("South", "Northeast", "North Central", "West"), col=c("red", "blue", "hotpink", "green"),lty=1, bty="n")
```

```{r}
#Racial category
cat1 <- lm(wage96~ black + hispanic, data=hw) #Wage difference compared to white
summary(cat1)

sink <- lm(wage96~ male+ norcen96+west96+south96+ black + hispanic, data=hw)
summary(sink)
```

Summarizing regression models

```{r}
#Yesterday we used model summary, today we will use stargazer to create nice regression tables
library("stargazer")
stargazer(ck1a,reg3, sink, type="text", title = "Multivariate Regression Models")

#We can also use the coefplot package. 
library(coefplot)#New Package. Will need to install. Also makes coefficient plots

coefplot(ck1a)#point is equal to coefficient. Lines are confidence interval. When CI does not overlap 0 coefficient is significant
coefplot(reg2)
coefplot(sink, intercept = FALSE, newNames=c(hispanic="Hispanic", black="Black", south96="South", west96="West", norcen96="North Central", male="Male"), title="Predictors of Wage \n 1996", xlab="")

multiplot(sink, reg2, intercept=FALSE)


coefplot(ck2, intercept = FALSE)#remember comparing size of effect only makes sense when range is the same. 
```

Bonus: Based on your extensive knowledge of American wages and statistics create your version of the best regression model(or models) Double Bonus: Create a table using stargazer

```{r}

```

############################# 

Lets play a bit more with regression assumptions and transforming variables

```{r}
# Restrict to employed respondents with complete height data
hwdata2 <- subset(hw, !is.na(wage96) & wage96 > 0 & !is.na(height85))

hwdata2$lwage <- log(hwdata2$wage96)   # log hourly wage
```

## Why Log Wages?

```{r}
#| fig-height: 3.2
par(mfrow = c(1, 2))
hist(hwdata2$wage96, main = "Raw Wage",      xlab = "Hourly Wage (USD)")
hist(hwdata2$lwage,  main = "log(Wage)",     xlab = "Log Hourly Wage")
```

- Raw wages are **right-skewed** — a few very high earners pull the tail
- Log transformation compresses the scale and produces an approximately normal distribution
- Interpretation shifts: a 1-inch increase in height is associated with a **percentage change** in wages

## Scatter Plot: Height and Log Wages

```{r}
#| fig-height: 3.8
plot(hwdata2$lwage ~ hwdata2$height85,
     xlab = "Height in 1985 (inches)",
     ylab = "Log Hourly Wage (1996)")

abline(lm(lwage ~ height85, data = hwdata2), col = "red")
```

- Is there a positive relationship? Does it look roughly linear?
- Outliers at the extremes are worth noting

## Compare: Logged vs. Unlogged Outcome

```{r}
model.wage.orig <- lm(wage96 ~ height85, data = hwdata2)
model.wage      <- lm(lwage  ~ height85, data = hwdata2)

modelsummary(
  list("Original" = model.wage.orig, "Log Outcome" = model.wage),
  stars  = c("*" = .1, "**" = .05, "***" = .01),
  output = "kableExtra"
)
```

- Compare $R^2$, residual standard error, and residual patterns
- Logged model: coefficient interpreted as *"a 1-inch increase in height is associated with a* $\hat{\beta} \times 100\%$ change in wages"

# Regression Diagnostics {.center}

## The Four Diagnostic Plots

```{r}
par(mfrow = c(2, 2))
plot(model.wage, labels.id = rownames(hwdata2))
```

Four plots, four questions:

1.  **Residuals vs. Fitted** — is the relationship linear? Should hug the dashed line
2.  **Normal Q-Q** — are errors normally distributed? Points should follow the diagonal
3.  **Scale-Location** — is variance constant (homoskedasticity)? Should be flat, no V-shape
4.  **Residuals vs. Leverage** — are any observations disproportionately influential? (Cook's distance)

## Reading Each Plot

::::: columns
::: {.column width="50%"}
**Residuals vs. Fitted**

- Curve or U-shape → **non-linearity** (try a transformation)
- Fan shape → **heteroskedasticity** (use robust SE)
- Should be random scatter around zero
:::

::: {.column width="50%"}
**Residuals vs. Leverage**

- Points outside Cook's distance contour are **high-influence**
- High leverage $\neq$ bad, but worth inspecting
- Ask: does the result change substantially if I drop this case?
:::
:::::

## Removing Outliers — With Caution

```{r}
# Identify high-wage outliers (e.g., top 1%)
wage_cutoff <- quantile(hwdata2$wage96, 0.99, na.rm = TRUE)#fance way to take out outleirs
hwdata4 <- subset(hwdata2, wage96 < wage_cutoff)

model2.wage <- lm(lwage ~ height85, data = hwdata4)
summary(model2.wage)

par(mfrow = c(2, 2))
plot(model2.wage, labels.id = rownames(hwdata4))
```

::: alertblock
**Warning:** Only remove observations if you have a **substantive theoretical reason**. Removing outliers to improve fit is data manipulation. Here we may want to keep high earners — they are real data points.
:::

# Part 3: Multicollinearity {.center}

## A Richer Model

```{r}
# Predict log wages with height plus controls
model6 <- lm(lwage ~ height85 + hgc96 + male + daded79 + momed79,
             data = hwdata2)
modelsummary(model6)
```

- Unit of analysis: **individual respondent**
- Are father's education (`daded79`) and mother's education (`momed79`) correlated with each other?

## The Problem: Correlated Predictors

```{r}
par(mfrow = c(1, 1)) #back to one pane
plot(hwdata2$daded79, hwdata2$momed79,
     xlab = "Father's Education (years)",
     ylab = "Mother's Education (years)")

cor(hwdata2$daded79, hwdata2$momed79, use = "complete")
```

- Parents' education levels tend to be correlated — assortative mating
- Putting both in the same model asks OLS to separate effects it cannot easily distinguish

## Fit the Model and Check VIF

```{r}
library(car)
vif(model6)
```

- VIF $>$ 5: warrants inspection
- VIF $>$ 10: serious problem — coefficients are unreliable
- Note how individual coefficients may be insignificant even when the overall model fits well

## Inspect the Diagnostics

```{r}
par(mfrow = c(2, 2))
plot(model6, labels.id = rownames(hwdata2))
```

Also compare single-predictor models to the joint model:

```{r}
summary(lm(lwage ~ daded79, data = hwdata2))
summary(lm(lwage ~ momed79, data = hwdata2))
```

If each predictor is significant alone but not together, that is a classic **multicollinearity signature.**

# All-in-one Regression Diagnostic package

```{r}
model9 <- lm(lwage ~ height85 + hgc96 + male +
               daded79 + momed79 + esteem80,
             data = hwdata2)


# install.packages("gvlma")
library(gvlma)

model9 <- lm(lwage ~ height85 + hgc96 + male +
               daded79 + momed79 + esteem80,
             data = hwdata2)

summary(gvlma(model9))
```

| Test               | Null hypothesis ($H_0$)            |
|--------------------|------------------------------------|
| Global Stat        | Relationship is linear             |
| Skewness           | Errors are not skewed              |
| Kurtosis           | Errors are not kurtotic            |
| Link Function      | DV is continuous (not categorical) |
| Heteroscedasticity | Residual variance is constant      |

Reject ($p < .05$) = assumption violated.

## `performance` — Modern Alternative

# install.packages("performance")



```{r}
library(performance)

check_autocorrelation(model9)
check_normality(model9)
check_collinearity(model9)
check_heteroskedasticity(model9)
model_performance(model9)


```

| Check | Tool |
|----|----|
| Right-skewed outcome or predictor? | `hist()` $\to$ log-transform |
| Non-linearity? | Residuals vs. Fitted plot |
| Heteroskedasticity? | Scale-Location plot; `bptest()` |
| Influential outliers? | Residuals vs. Leverage; Cook's distance |
| Multicollinearity? | `cor()`; `vif()` |
| Autocorrelation? | `durbinWatsonTest()` |
| All at once? | `check_model()` or `summary(gvlma())` |

------------------------------------------------------------------------

Remember: violating these assumptions does not always mean **bias** — it usually means your **standard errors are wrong**, which corrupts inference even when coefficients look reasonable.

###### Some Experiments Basics

# Experiments

Set working directory and unpack packages

```{r}
#install.packages("pwr")
#install.packages("AER")
library(haven)
library(tidyverse)
library(pwr)
library(AER)


#More info here: https://www.statmethods.net/stats/power.html
```

Recall, with experiments we're focused more on design than statistical analysis.

#Practice data from the textbook.

```{r}
GGD <- read_csv("GerberGreenData.csv")
summary(GGD)


#check balance across wards
b1 <- table(GGD$Ward, GGD$ContactAssigned)
prop.table(b1, 1) #Balance looks good. 
summary(lm(GGD$ContactAssigned~GGD$Ward)) # Can run T-test or regression to see if sig dif. Ward is not correlated with treatment assignment

#across # of people in household
b2 <- table(GGD$PeopleHH, GGD$ContactAssigned)
prop.table(b2, 1)

#use dplyr
balance <- GGD %>% group_by(ContactAssigned)%>% summarise(People=mean(PeopleHH), Ward=mean(Ward))
t(balance)


#Experimental results: Does talking to people increase likelihood of voting? 

#ITT does being assigned to treatment actually effect the likilood of voting(regardless of compliance)?
ITT <-(lm(GGD$Voted~GGD$ContactAssigned))
summary(ITT)

#Voting is dummy variable and this is experimental. When we use OLS on a dummy we call it a linear probablity model and it is interpreted as percentage change in Y from a one unit change in X. An advanced class would talk about the advantages of LPM vs logit or probit for binary DVs.  

#What variables are we missing from our model?

summary(lm(Voted ~ ContactAssigned+Ward+PeopleHH, data=GGD))#adding controls does not change coefficient, only signifigance

#Compliance: 
  
#ATE model
ATE <-(lm(GGD$Voted~GGD$ContactObserved)) #The effect of actually being treated
summary(ATE)


#percentage of those assigned to treatment actually treated
summary(lm(ContactObserved ~ ContactAssigned, data=GGD))#table 10.2 in book. 

twosls <- ivreg(Voted ~ ContactObserved | ContactAssigned, data=GGD) 
summary(twosls)



stargazer(ATE,ITT, twosls,  type="text", title = "Comparison of Experimental Models")


multiplot(ATE,ITT, twosls, title = "Comparison of Experimental Models", xlab="Effect Size(Percentage)", intercept=FALSE)

```

Heterogeneous Treatment Effects

```{r}
#We have limited data, but say we were interested in if the effect of contact was dependent on the number of people in the household

hhe <- (lm(Voted~ContactObserved*PeopleHH, data=GGD))
summary(hhe)
```

I haven't used it much, but DeclareDesign has good stuff on thinking through experimental designs (<https://declaredesign.org/r/declaredesign/>)
